package com.zyz.order.service;

import com.zyz.order.mapper.OrderMapper;
import com.zyz.order.model.OrderInfo;
import com.zyz.product.api.ProductInterface;
import com.zyz.product.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProductInterface productApi;

    public OrderInfo selectOrderById(Integer id) {
        OrderInfo orderInfo = orderMapper.selectOrderById(id);
//        String url = "http://product-service/product/" + orderInfo.getProductId();
//        ProductInfo getProductInfo = restTemplate.getForObject(url, ProductInfo.class);
        ProductInfo productInfo = productApi.getProductInfo(orderInfo.getProductId());
        orderInfo.setProductInfo(productInfo);
        return orderInfo;
    }
}
